<!-- 131 create by hxg 2021/12/17 -->
<template>
  <div>
    <a-space class="common-button-group">
      <a-button type="primary" :loading="searchBtnLoading" @click="getList">{{
        $t("common_query")
      }}</a-button>
    </a-space>
    <t-query-form
      layout="inline"
      ref="queryForm"
      group="HoldCst"
      :model="queryForm"
    >
      <a-row :gutter="[16, 0]">
        <a-col :span="6">
          <a-form-item
            :label="$t('T9_shopId')"
            name="shopId"
            prop="shopId"
            :rules="{
              required: true,
              message: $t('T9_shopId'),
              trigger: 'change',
            }"
          >
            <a-select
              v-model:value="queryForm.shopId"
              class="select-width"
              @change="changeShopId"
            >
              <a-select-option
                v-for="item in shopIdArr"
                :key="item.shopId"
                :value="item.shopId"
              >
                {{ item.shopId }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item
            :label="$t('T9_type')"
            name="type"
            prop="type"
            :rules="{
              required: true,
              message: $t('T9_type'),
              trigger: 'change',
            }"
          >
            <a-select
              v-model:value="queryForm.type"
              class="select-width"
              @change="changeShopId"
            >
              <a-select-option
                v-for="item in typeArr"
                :key="item.type"
                :value="item.type"
              >
                {{ item.type }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item
            :label="$t('T9_cstSpec')"
            name="cstSpec"
            prop="cstSpec"
            :rules="{
              required: true,
              message: $t('T9_cstSpec'),
              trigger: 'change',
            }"
          >
            <a-select
              v-model:value="queryForm.cstSpec"
              class="select-width"
              @change="changeCstSpec"
            >
              <a-select-option
                v-for="item in cstSpecArr"
                :key="item.cstSpec"
                :value="item.cstSpec"
              >
                {{ item.cstSpec }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item
            :label="$t('T9_cstId')"
            name="cstId"
            prop="cstId"
            :rules="{
              required: true,
              message: $t('T9_cstId'),
              trigger: 'change',
            }"
          >
            <a-select v-model:value="queryForm.cstId" class="select-width">
              <a-select-option
                v-for="item in cstIdArr"
                :key="item"
                :value="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
    </t-query-form>
    <a-row
      type="flex"
      justify="space-between"
      align="middle"
      class="global-oper-row mt-2"
    >
      <a-col :span="17" class="global-oper-row-title">{{
        $t("T9_cstList")
      }}</a-col>
      <a-col :span="3" class="global-oper-row-extra">
        <a-button>{{ $t("t9_toExcel") }}</a-button>
      </a-col>
    </a-row>
    <t-table :data="table.data">
      <t-column field="cstId" :title="$t('T9_cstId')" />
      <t-column field="cstState" :title="$t('T9_cstState')" />
      <t-column field="cleanState" :title="$t('T9_cleanState')" />
      <t-column field="holdState" :title="$t('T9_holdState')" />
      <t-column field="reasonCode" :title="$t('T9_reasonCode')" />
      <t-column field="transferState" :title="$t('T9_transferState')" />
      <t-column field="eqpId" :title="$t('T9_eqpId')" />
      <t-column field="pitch" :title="$t('T9_pitch')" />
      <t-column field="timeUsedLimt" :title="$t('T9_timeUsedLimt')" />
      <t-column field="maxUsedDaysLimit" :title="$t('T9_maxUsedDaysLimit')" />
      <t-column field="capacity" :title="$t('T9_capacity')" />
      <t-column field="createUser" :title="$t('T9_createUser')" />
    </t-table>
    <t-query-form
      layout="inline"
      ref="dataForm"
      :model="footForm"
      class="footQueryForm"
      style="flex-direction: column;"
    >
      <a-row :gutter="[0, 0]">
        <a-col :span="24" style="margin-right:10px">
          <a-form-item
            :label="$t('T9_reasonCode')"
            name="reasonCode"
            prop="reasonCode"
            :rules="{
              required: true,
              message: $t('T9_reasonCode'),
              trigger: 'change',
            }"
            style="width: 30%"
          >
            <a-select v-model:value="dataForm.reasonCode" class="select-width">
              <a-select-option
                v-for="item in reasonCodeArr"
                :key="item"
                :value="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 0]">
        <a-col :span="24">
          <a-form-item
            :label="$t('T9_comment')"
            name="comment"
            prop="comment"
            :rules="{
              required: true,
              message: $t('T9_comment'),
              trigger: 'change',
            }"
          >
            <a-input v-model:value="dataForm.comment" />
          </a-form-item>
        </a-col>
      </a-row>
    </t-query-form>
    <div class="footBtn">
      <a-button type="primary">{{ $t("T9_confirm") }}</a-button>
    </div>
  </div>
</template>

<script>
  import { defineComponent } from 'vue'
  import moment from 'moment'
  import {
    getShopId,
    getBayId,
    getEqpId,
    getPortId,
    getOwnerType,
    getOwnerId,
    getList
  } from '@/api/common'
  import { getCurrentDate } from '@/utils/utils'

  export default defineComponent({
    name: 'HoldCst',
    components: {},
    data() {
      return {
        searchBtnLoading: false,
        table: {
          list: []
        },
        shopIdArr: [],
        cstIdArr: [],
        boxIdArr: [],
        queryForm: {
          shopId: 'CELL',
          cstId: '',
          boxId: ''
        },
        dataForm: {
          comment: ''
        }
      }
    },
    computed: {},
    watch: {},
    created() {
      this.getBayId()
      this.getShopId()
      // this.getOwnerType()
      this.queryForm.Date = [
        moment(getCurrentDate(), 'YYYY-MM-DD HH:mm'),
        moment(getCurrentDate(1), 'YYYY-MM-DD HH:mm')
      ]
    },
    methods: {
      onChange(value, dates) {
        this.queryForm.Date = dates
        console.log('Selected Time: ', this.queryForm.Date[0])
      },
      getList() {
        const obj = {
          dtoName: 'PortHistoryDTO',
          startTime:
            this.queryForm.Date.length !== 0
              ? this.queryForm.Date[0].format('YYYYMMDDHHmmss') * 1000
              : null,
          endTime:
            this.queryForm.Date.length !== 0
              ? this.queryForm.Date[1].format('YYYYMMDDHHmmss') * 1000
              : null,
          eqpId: this.queryForm.eqpId,
          portId: this.queryForm.portId,
          queryId: 'GetPortHistoryList',
          version: '80002',
          menuName: 'portHistory',
          usage: 'queryPortHistoryList'
        }
        getList(obj).then((res) => {
          this.table = res
        })
      },
      handleSearch() {},
      changeShopId(val) {
        if (val) {
          this.getBayId()
        }
      },
      changeCstSpec() {},
      changeOwnerType(val) {
        if (val) {
          this.getOwner()
        }
      },
      changeBayId(val) {
        if (val) {
          this.getEqpId()
        }
      },
      getShopId() {
        const params = {
          userGroup: 'CellPIOper'
        }
        getShopId(params).then((res) => {
          this.shopIdArr = res
        })
      },
      getBayId() {
        const params = {
          shopId: this.queryForm.shopId
        }
        getBayId(params).then((res) => {
          this.bayIdArr = res
        })
      },
      getEqpId() {
        const params = {
          bayId: this.queryForm.bayId,
          shopId: this.queryForm.shopId
        }
        getEqpId(params).then((res) => {
          this.eqpIdArr = res
        })
      },
      getPortIdList() {
        const params = {
          eqpId: this.queryForm.eqpId
        }
        getPortId(params).then((res) => {
          this.portIdArr = res
        })
      },
      getOwnerType() {
        getOwnerType().then((res) => {
          this.ownerTypeArr = res
        })
      },
      getOwner() {
        const params = {
          ownerType: this.queryForm.ownerType,
          shopId: this.queryForm.shopId
        }
        getOwnerId(params).then((res) => {
          this.ownerArr = res
        })
      }
    }
  })
</script>
<style lang="less" scoped>
/deep/ .ant-row,
.ant-row:after,
.ant-row:before {
  display: flex;
  flex: 1;
}
.footBtn {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
